<?php

use common\models\Comment;
use yii\helpers\Html;
use yii\helpers\Url;
use yii\grid\ActionColumn;
use yii\grid\GridView;
use common\models\Commentstatus;


/** @var yii\web\View $this */
/** @var common\models\CommentSearch $searchModel */
/** @var yii\data\ActiveDataProvider $dataProvider */

$this->title = '报名管理';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="comment-index">

    <h1><?= Html::encode($this->title) ?></h1>

    <p>
        <?= Html::a('新增评论', ['create'], ['class' => 'btn btn-success']) ?>
    </p>

    <?php // echo $this->render('_search', ['model' => $searchModel]); ?>

    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'columns' => [
            ['class' => 'yii\grid\SerialColumn'],

            [
            'attribute'=>'id',
            'contentOptions'=>['width'=>'30px'],
            ],
            [
            'attribute'=>'content',
            'value'=>function($model)//设置content长度不超过20个字符
                 {
                     $tmpStr=strip_tags($model->content);
                     $tmpLen=mb_strlen($tmpStr);         
                     return mb_substr($tmpStr,0,20,'utf-8').(($tmpLen>20)?'...':'');
                 }
            ],

            [
            'attribute'=>'user.username',
            'label'=>'作者',
            'value'=>'user.username',   
            ],

            [
            'attribute'=>'status',
            'value'=>'status0.name',
            'filter'=>Commentstatus::find()
                      ->select(['name','id'])
                      ->orderBy('position')
                      ->indexBy('id')
                      ->column(),
            'contentOptions'=>//设置底色
                    function($model)
                    {
                        return ($model->status==1)?['class'=>'bg-danger']:[];
                    }
            ],
            [
                'attribute'=>'create_time',
                'format'=>['date','php:Y-m-d H:i:s'],
            ],
            
            //'email:email',
            //'url:url',
            //'post_id',

            'post.title',
            [
                'class' => ActionColumn::className(),
                'urlCreator' => function ($action, Comment $model, $key, $index, $column) {
                    return Url::toRoute([$action, 'id' => $model->id]);
                 }
            ],
        ],
    ]); ?>


</div>
